package test;

import std::IO;
import std::Type;
import std::collection::Collection;
import std::collection::Map;
import std::collection::Iterator;

import std::collection::LinkedList;
import std::collection::ArrayList;

import std::collection::TreeSet;
import std::collection::HashSet;

import std::collection::HashMap;
import std::collection::TreeMap;

class TestIterator{
	public static test(){
		IO.printf("测试list迭代器\n");
		TestIterator.testCollection(new LinkedList());
		IO.printf("\n测试vector迭代器\n");
		TestIterator.testCollection(new ArrayList());
		IO.printf("\n测试hashset迭代器\n");
		TestIterator.testCollection(new HashSet(40));
		IO.printf("\n测试treeset迭代器\n");
		TestIterator.testCollection(new TreeSet());
		IO.printf("\n测试hashmap迭代器\n");
		TestIterator.testMap(new HashMap());
		IO.printf("\n测试treemap迭代器\n");
		TestIterator.testMap(new TreeMap());
	}

	static testCollection(v->Collection){
		i->int=0;
		while(i<50)v.add(Type.get(i++));
		itr->Iterator=v.iterator();
		while(itr.hasNext()){
			IO.printf("%d ", itr.next()->(Type));
		}
	}

	static testMap(v->Map){
		i->int=0;
		while(i<50)v.put(Type.get(i), Type.get(100+i++));
		itr->Iterator=v.keys();
		IO.printf("键:");
		while(itr.hasNext()){
			IO.printf("%d ", itr.next()->(Type));
		}
		itr=v.values();
		IO.printf("\n值:");
		while(itr.hasNext()){
			IO.printf("%d ", itr.next()->(Type));
		}
	}
}